package abc.com.abc.activity;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Set;

import abc.com.abc.R;
import abc.com.abc.view.MyInfoView;

public class SettingActivity extends AppCompatActivity {
    private TextView tv_main_title;
    private TextView tv_back;
    private RelativeLayout rl_title_bar;
    private RelativeLayout rl_modify_psw,rl_security_setting,rl_person,rl_exit_login;
    public static SettingActivity instance = null;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        //设置竖屏
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        instance = this;
        init();
    }

    private void init() {
        //用户名显示页面


        tv_main_title=findViewById(R.id.tv_main_title);
        tv_main_title.setText("设置");
        tv_back = findViewById(R.id.tv_back);
        rl_title_bar = findViewById(R.id.title_Bar);
        rl_title_bar.setBackgroundColor(Color.parseColor("#30b4ff"));
        rl_modify_psw=findViewById(R.id.rl_modify_psw);
        rl_security_setting =findViewById(R.id.rl_security_setting);
        rl_person = findViewById(R.id.rl_person_setting);

        rl_exit_login = findViewById(R.id.rl_exit_login);
        tv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SettingActivity.this.finish();
            }
        });
        //修改密码的点击事件
        rl_modify_psw.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //跳转到修改密码界面
                Intent intent = new Intent(SettingActivity.this,ModifyPsw_Activity.class);

                startActivity(intent);
            }
        });
        rl_security_setting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //跳转到设置密保页面
                Intent intent = new Intent(SettingActivity.this,FindPswActivity.class);
                intent.putExtra("from","security");
                startActivity(intent);
            }
        });
        rl_person.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //跳转到个人信息页面
                Intent intent = new Intent(SettingActivity.this,UserInfoActivity.class);
                startActivity(intent);
            }
        });
        rl_exit_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //跳转到退出登录
                Toast .makeText(SettingActivity.this,"退出登录成功",Toast.LENGTH_LONG).show();
             cleanLoginStatus();//清除用户名
                finish();
                Intent data = new Intent();
               data.putExtra("isLogin",false);
              setResult(RESULT_OK,data);
                Intent intent = new Intent(SettingActivity.this,LoginActivity.class);
                startActivity(intent);


            }
        });

    }
//清除sharedpreferences中的登陆状态和用户名
    private void cleanLoginStatus() {
        SharedPreferences sp = getSharedPreferences("loginInfo",Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean("isLogin",false);
        editor.putString("loginUserName","");
        editor.commit();


    }
}
